<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm"  label-position="right" label-width="200px" class="demo-ruleForm" size="large" >
    <el-form-item label="ItemID">
      <el-input v-model="ruleForm.itemId" readonly style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="ProductID" prop="productId">
      <el-input v-model="ruleForm.productId"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="ListPrice" prop="listPrice">
      <el-input v-model="ruleForm.listPrice"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="UnitCost" prop="unitCost">
      <el-input v-model="ruleForm.unitCost"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="Supplier" prop="supplierId">
      <el-input v-model="ruleForm.supplierId"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="Status" prop="status">
      <el-input v-model="ruleForm.status"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="Quantity" prop="quantity">
      <el-input v-model="ruleForm.quantity"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="Attribute1" prop="attribute1">
      <el-input v-model="ruleForm.attribute1"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="Attribute2" prop="attribute2">
      <el-input v-model="ruleForm.attribute2"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="Attribute3" prop="attribute3">
      <el-input v-model="ruleForm.attribute4"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="Attribute4" prop="attribute4">
      <el-input v-model="ruleForm.attribute4"style="width:300px"></el-input>
    </el-form-item>
    <el-form-item label="Attribute5" prop="attribute5">
      <el-input v-model="ruleForm.attribute5"style="width:300px"></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="primary" @click="submitForm('ruleForm')">修改</el-button>
      <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        itemId:this.$route.query.itemId,
        productId:this.$route.query.productId ,
        listPrice:this.$route.query.listPrice,
        unitCost:this.$route.query. unitCost,
        supplierId:this.$route.query.supplierId,
        status:this.$route.query.status,
        attribute1:this.$route.query.attribute1,
        attribute2:this.$route.query.attribute2,
        attribute3:this.$route.query.attribute3,
        attribute4:this.$route.query.attribute4,
        attribute5:this.$route.query.attribute5,
        quantity: this.$route.query.quantity
      },
      rules: {
        productId: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        listPrice: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        supplierId: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        unitCost: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        status: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        attribute1: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        attribute2: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        attribute3: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        attribute4: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        attribute5: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ],
        quantity: [
          { required: true, message: '请输入正确的内容', trigger: 'blur' },
        ]

      }
    };
  },
  methods: {
    submitForm(formName) {
      const _this=this;
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios({
            method: "PUT",
            url: 'http://115.29.176.82:8081/manager/api/item',
            data: {
              productId: _this.ruleForm.productId,
              itemId: _this.ruleForm.itemId,
              listPrice: _this.ruleForm.listPrice,
              unitCost: _this.ruleForm.unitCost,
              supplierId: _this.ruleForm.supplierId,
              status: _this.ruleForm.status,
              attribute1: _this.ruleForm.attribute1,
              attribute2: _this.ruleForm.attribute2,
              attribute3: _this.ruleForm.attribute3,
              attribute4: _this.ruleForm. attribute4,
              attribute5: _this.ruleForm.attribute5,
              quantity: _this.ruleForm.quantity,
            }
          }).then(function (resp) {
            console.log(resp)
            if (resp.status ===200)
              alert('修改成功，请继续您的操作')
          })
        } else {
          alert('ERROR！请修改您的数据后再次提交')
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created() {
    const _this=this
  }
}
</script>